<template>
	<view class="container">
		<Header :isBack="true">
			<block slot="content">{{title}}</block>
		</Header>

		<view v-show="!isLoading">
			<view class="guess-section">
				<view class="guess-items" v-for="items in cateList" :key="items.id">
					<view class="cate-title" v-if="cid == items.cid">
						{{items.name}}
					</view>
					<view class="guess-item" v-for="item in items.child" :key="item.id"
						@tap="getWorker(item.cid, item.name)">
						<!-- <view class="image-wrapper">
							<image :src="item.img1"></image>
						</view> -->
						<view class="image-wrapper" style="overflow: inherit !important;">
							<view class="" style="position: relative;">
								<image :src="item.img1"></image>
								<view v-if="item.view_count && cate==1"
									style="line-height:40rpx;text-align:center;width: 40rpx;height: 40rpx;padding:0 4rpx;position: absolute;right: -25rpx;top:-15rpx;background: #f3431a;color:#fff;font-size: 24rpx;border-radius: 20rpx;">
									{{item.view_count}}</view>
							</view>
						</view>
						<text class="title clamp">{{item.name}}</text>
					</view>
				</view>
			</view>

			<!-- <view class="goods-lists" v-if="goodsList.length > 0">
				<view class="goods-lists-header">
					<view class="goods-lists-header-left">
						<image class="goods-lists-header-left-img" src="@/static/images/zuogang.png"></image>
						<text class="goods-lists-header-left-text">推荐工具</text>
					</view>
				</view>
				<view class="goods-list">
					<view v-for="(item, index) in goodsList" :key="index" class="goods-item"
						@click="navToDetailPage(item)">
						<view class="image-wrapper">
							<image :src="item.cover_ico" mode="aspectFit"></image>
						</view>
						<text class="title clamp">{{item.product_name}}</text>
						<view class="price-box">
							<text class="price">{{item.member_price}}</text>
							<text>已售 {{item.sell_num}}</text>
						</view>
					</view>
				</view>
			</view> -->
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {

		data() {
			return {
				title: '',
				cid: '',
				cateList: [],
				//弹出框
				isLoading: true,

				cate: 1,
				isCate: false,
				// goodsList: [],
			};
		},
		components: {

		},
		// computed: {
		// 	...mapState(['hasLogin']),
		// },
		async onLoad(option) {
			uni.showLoading({
				title: '加载中...'
			});

			this.title = '工种分类';
			this.cid = option.cid;

			if ([1, 2].indexOf(uni.getStorageSync('cate')) > -1) {
				this.cate = uni.getStorageSync('cate')
			}

			this.loadData(option.cid);
			uni.hideLoading();
			this.isLoading = false;
		},
		methods: {
			async loadData(cid) {
				this.getPositions(cid);
			},

			async getPositions(cid) {
				let osecCates = await this.$myRequest({
					url: '/common/allPositions',
					data: {
						token: uni.getStorageSync('token'),
						cid: cid
					}
				});

				let data = osecCates.data.data;
				this.cateList = data.positions || [];
				// this.goodsList = data.products || [];
			},

			async getWorker(cid, title) {
				if (this.cate == 2) {
					let result = this.$api.isLogin();
					if (result === false) {
						return false;
					}
					uni.navigateTo({
						url: '/pages3/pages/publish-job/publish-job?cid=' + cid + '&title=' + title
					})
				} else {
					uni.navigateTo({
						url: '/pages1/pages/project-item/project-item?cid=' + cid + '&title=' + title
					})
				}
			},

			//详情
			navToDetailPage(item) {
				//测试数据没有写id，用title代替
				let id = item.id;
				uni.navigateTo({
					url: `/pages6/pages/product/product?id=${id}`
				})
			},
		},
	}
</script>
<style>
	page {
		background-color: #F7F7F7;
		font-size: $font-base;
	}
</style>
<style lang="scss" scoped>
	.guess-section {
		display: flex;
		flex-wrap: wrap;
		// #ifdef APP-PLUS
		padding-top: 152rpx;
		// #endif

		// #ifdef H5
		padding-top: 100rpx;
		// #endif

		// #ifdef MP-WEIXIN
		padding-top: 152rpx;
		// #endif

	}

	.guess-items {
		width: 100%;
		margin: 16upx 16upx 0;
		border-radius: 10upx;
		background: #fff;
		padding-bottom: 30upx;
	}

	.cate-title {
		width: 166upx;
		height: 60upx;
		background-color: $base-color;
		margin: 0 auto;
		font-size: $font-base;
		color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		border-bottom-left-radius: 10upx;
		border-bottom-right-radius: 10upx;
	}

	.guess-item {
		display: inline-flex;
		flex-direction: column;
		width: 33.3%;
		padding-top: 30upx;
		font-size: $font-base - 2upx;

		.image-wrapper {
			width: 100%;
			background: #fff;
			overflow: hidden;
			display: flex;
			justify-content: center;
			margin-bottom: 17upx;

			image {
				width: 96upx;
				height: 96upx;
				opacity: 1;
			}
		}

		.title {
			display: flex;
			justify-content: center;
			color: #333;
			font-size: $font-base;
		}
	}

	/* 商品列表 */
	.goods-lists {
		border-top: 1px solid #ececec;
		// padding: 0 30upx;
		width: 100%;
	}

	.goods-lists-header {
		height: 112rpx;
		padding: 0 32rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.goods-lists-header-left {
			display: flex;
			align-items: center;
		}

		.goods-lists-header-left-img {
			width: 6rpx;
			height: 27rpx;
			margin-right: 16rpx;
		}

		.goods-lists-header-left-text {
			/* font-weight: bold; */
			font-size: $font-base;
		}

		.goods-lists-header-right-text {
			font-size: $font-base;
			color: $font-color-dark;
			margin-right: 18rpx;
		}

		.goods-lists-header-right-img {
			width: 9rpx;
			height: 18rpx;
		}
	}

	.goods-list {
		padding: 0 30upx;

		width: 100%;
		display: flex;
		flex-wrap: wrap;
		// background: #fff;

		.goods-item {
			display: flex;
			flex-direction: column;
			width: 48%;
			padding-bottom: 40upx;

			&:nth-child(2n+1) {
				margin-right: 4%;
			}
		}

		.image-wrapper {
			width: 100%;
			width: 330upx;
			height: 330upx;
			border-radius: 3px;
			overflow: hidden;

			image {
				width: 100%;
				height: 100%;
				opacity: 1;
			}
		}

		.title {
			font-size: $font-base;
			color: $font-color-dark;
			line-height: 80upx;
		}

		.price-box {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-right: 10upx;
			font-size: 24upx;
			color: $font-color-light;
		}

		.price {
			font-size: $font-base;
			color: $uni-color-primary;
			line-height: 1;

			&:before {
				content: '￥';
				font-size: 26upx;
			}
		}
	}
</style>